package com.cyandpos.pad.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.cyandpos.pad.R;
import com.cyandpos.pad.activity.attachfunction.MemberCentActivity;
import com.cyandpos.pad.activity.attachfunction.MemberCodedCouponQueryActivity;
import com.cyandpos.pad.activity.attachfunction.MemberCouponActivity;
import com.cyandpos.pad.activity.attachfunction.ValueCardActivity;
import com.cyandpos.pad.attachselect.presenter.IMemberPresenter;
import com.cyandpos.pad.attachselect.presenter.MemberPresenterImpl;
import com.cyandpos.pad.attachselect.view.IMemberView;
import com.cyandpos.pad.common.commondata.Constant;
import com.cyandpos.pad.posdata.GetValueCardResponse;
import com.cyandpos.pad.posdata.GetVipCouponResponse;
import com.cyandpos.pad.posdata.QueryMemberInfoResponse;
import com.cyandpos.pad.sale.view.SelfNumKeyView;
import com.cyandpos.pad.utils.CommonUtils;
import com.cyandpos.pad.utils.MemberUtils;
import com.cyandpos.pad.utils.PayUtil;
import com.cyandpos.pad.utils.ToastUtils;

import butterknife.BindView;

public class FjcxActivity extends  BaseActivity implements IMemberView,View.OnClickListener {
    @BindView(R.id.btn_czkye)
    Button btn_czkye;
    @BindView(R.id.btn_hykjf)
    Button btn_hykjf;
    @BindView(R.id.btn_kqcx)
    Button btn_kqcx;
    @BindView(R.id.btn_cxdfq)
    Button btn_cxdfq;
    @BindView(R.id.btn_qxqmq)
    Button btn_qxqmq;
    @BindView(R.id.btn_qtzc)
    Button btn_qtzc;
    @BindView(R.id.btn_crmcz)
    Button btn_crmcz;
    @BindView(R.id.btn_crmzzdz)
    Button btn_crmzzdz;
    @BindView(R.id.btn_ddzfp)
    Button btn_ddzfp;
    @BindView(R.id.tv_dialog_title_name)
    TextView tv_dialogtitle_name;
    public static AlertDialog mDialog;//所有dialog
    private static IMemberPresenter mMemberPresenterImpl;

    @Override
    protected void initData() {
        mMemberPresenterImpl = new MemberPresenterImpl(this);

        btn_czkye.setOnClickListener(this);
        btn_hykjf.setOnClickListener(this);
        btn_kqcx.setOnClickListener(this);
        btn_cxdfq.setOnClickListener(this);
        btn_qxqmq.setOnClickListener(this);
        btn_qtzc.setOnClickListener(this);
        btn_crmcz.setOnClickListener(this);
        btn_crmzzdz.setOnClickListener(this);
        btn_ddzfp.setOnClickListener(this);
        tv_dialogtitle_name.setOnClickListener(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_fjcx;
    }

    @Override
    public void onClick(View v) {
         switch (v.getId()){
             case R.id.btn_czkye:
                 startActivity(new Intent(FjcxActivity.this, ValueCardActivity.class));
                 finish();
                 break;
             case R.id.btn_hykjf:
                 startActivity(new Intent(FjcxActivity.this, MemberCentActivity.class));
                 finish();
                 break;
             case R.id.btn_kqcx:
                 startActivity(new Intent(FjcxActivity.this, MemberCouponActivity.class));
                 finish();
                 break;
             case R.id.btn_cxdfq:
                 showQueryMemberDialog(FjcxActivity.this,"查询待返券");
                 break;
             case R.id.btn_qxqmq:
                 PayUtil.showQueryMemberDialog(FjcxActivity.this, Constant.MEMBER_IDENTIFYING_TRADE_ADD_MEMBER);
                 break;
             case R.id.btn_bmqcx://编码券查询
                 startActivity(new Intent(FjcxActivity.this, MemberCodedCouponQueryActivity.class));
                 finish();
                 break;
             case R.id.btn_qtzc:

                 break;
             case R.id.btn_crmzzdz:

                 break;
             case R.id.btn_ddzfp:

                 break;
             case R.id.tv_dialog_title_name:
                  finish();
                 break;
             default:
                 break;

         }
    }

    public static void showQueryMemberDialog(final Activity mContext, final String flag) {
        final View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_member, null);
        TextView tvName = view.findViewById(R.id.tv_dialog_title_name);
        final SelfNumKeyView sf_containt = view.findViewById(R.id.member_soft_keyboard);

        boolean isNeedInputView = false;//是否需要输入布局

        tvName.setText(flag);
        //关闭按钮
        tvName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDialog.dismiss();
            }
        });

        view.findViewById(R.id.tv_sale_member_swipe).setVisibility(View.GONE);
        view.findViewById(R.id.tv_sale_member_scan).setVisibility(View.GONE);
        view.findViewById(R.id.tv_sale_member_card).setVisibility(View.GONE);
        view.findViewById(R.id.tv_sale_member_phone).setVisibility(View.GONE);
        view.findViewById(R.id.tv_sale_member_idcard).setVisibility(View.GONE);

         if (flag.equals("储值卡余额")) {

             view.findViewById(R.id.tv_sale_member_swipe).setVisibility(View.VISIBLE);
             view.findViewById(R.id.tv_sale_member_scan).setVisibility(View.VISIBLE);
             view.findViewById(R.id.tv_sale_member_card).setVisibility(View.VISIBLE);
             view.findViewById(R.id.tv_sale_member_phone).setVisibility(View.VISIBLE);

             isNeedInputView = true;

         }
         if (flag.equals("会员卡积分")){
             view.findViewById(R.id.tv_sale_member_swipe).setVisibility(View.VISIBLE);
             view.findViewById(R.id.tv_sale_member_scan).setVisibility(View.VISIBLE);
             view.findViewById(R.id.tv_sale_member_card).setVisibility(View.VISIBLE);
             view.findViewById(R.id.tv_sale_member_phone).setVisibility(View.VISIBLE);
             isNeedInputView = true;

         }
         if (flag.equals("卡券查询")){
             view.findViewById(R.id.tv_sale_member_swipe).setVisibility(View.VISIBLE);
             view.findViewById(R.id.tv_sale_member_scan).setVisibility(View.VISIBLE);
             view.findViewById(R.id.tv_sale_member_card).setVisibility(View.VISIBLE);
             view.findViewById(R.id.tv_sale_member_phone).setVisibility(View.VISIBLE);
             isNeedInputView = true;

         } if (flag.equals("查询待返券")){
             view.findViewById(R.id.tv_sale_member_swipe).setVisibility(View.VISIBLE);
             view.findViewById(R.id.tv_sale_member_scan).setVisibility(View.VISIBLE);
             view.findViewById(R.id.tv_sale_member_card).setVisibility(View.VISIBLE);
             view.findViewById(R.id.tv_sale_member_phone).setVisibility(View.VISIBLE);
             isNeedInputView = true;
         }
        if(!isNeedInputView)
            sf_containt.setVisibility(View.GONE);//不需要输入布局

        //会员刷卡
        view.findViewById(R.id.tv_sale_member_swipe).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDialog.dismiss();
//                swipeCardtypeDialog(mContext,flag);
            }
        });
        //会员扫码
        view.findViewById(R.id.tv_sale_member_scan).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mDialog.dismiss();
//                scanCodeTypeDialog(mContext,flag);
            }
        });

        //卡号
        final EditText etCardNo = view.findViewById(R.id.et_sale_member_card);
        final TextView tvCardNo = view.findViewById(R.id.tv_sale_member_card);

        //手机号
        final EditText etPhone = view.findViewById(R.id.et_sale_member_phone);
        final TextView tvPhone = view.findViewById(R.id.tv_sale_member_phone);

        tvCardNo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                tvCardNo.setVisibility(View.GONE);
                etCardNo.setVisibility(View.VISIBLE);

                tvPhone.setVisibility(View.VISIBLE);
                etPhone.setVisibility(View.GONE);

                etPhone.setText("");
                etCardNo.setFocusable(true);
                sf_containt.setEnterReceptor(etCardNo);
                sf_containt.setOnCallBack(new SelfNumKeyView.SelfNumCallBack() {
                    @Override
                    public void keyBoardSure(String num,String hint) {
                        mDialog.dismiss();
                        ToastUtils.show("卡号开始查询会员");
                        //卡号事件
                    //     cardNoTypeDialog(mContext,flag,num);
                    }
                });
            }
        });
        CommonUtils.setNoSoftware(etCardNo, mContext,true);
        CommonUtils.setNoSoftware(etPhone, mContext,true);

        tvPhone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tvPhone.setVisibility(View.GONE);
                etPhone.setVisibility(View.VISIBLE);

                tvCardNo.setVisibility(View.VISIBLE);
                etCardNo.setVisibility(View.GONE);

                etCardNo.setText("");
                etPhone.setFocusable(true);
                sf_containt.setEnterReceptor(etPhone);
                sf_containt.setOnCallBack(new SelfNumKeyView.SelfNumCallBack() {
                    @Override
                    public void keyBoardSure(String num,String hint) {
                        mDialog.dismiss();
                        ToastUtils.show("手机号开始查询会员");
                        //手机号事件
                         // phoneTypeDialog(mContext,flag,num);


                     //   queryValueCard(content,0,"");


                    }
                });

            }
        });
        AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
        dialog.setView(view).setCancelable(false).create();
        mDialog = dialog.show();
    }



    @Override
    public void showMemberDetail(QueryMemberInfoResponse member) {

    }

    @Override
    public void showCouponDetail(GetVipCouponResponse GetVipCouponResponseData) {

    }

    @Override
    public void showCentDetail(QueryMemberInfoResponse member) {

    }

    @Override
    public void showValueCard(GetValueCardResponse responseData) {

    }

    @Override
    public void showWaitDialog(String content) {

    }

    @Override
    public void showMessage(String content) {

    }

    @Override
    public void dismissWaitDialog() {

    }

    @Override
    public void onFail(String content, int handleId) {

    }

    @Override
    public void onFail(String content) {

    }

    @Override
    protected void onResume() {
        super.onResume();
        tv_dialogtitle_name.setText("附加功能查询");
    }
}
